#include <reg52.h>
#include <..\XC51.h>

unsigned char pwm_left_val = 160;
unsigned char pwm_right_val = 160;
unsigned char pwm_t;

void timer0() interrupt 1
{
	pwm_t++;
	if(pwm_t == 255)
		pwm_t = EN1 = EN2 = 0;
	if(pwm_left_val == pwm_t)
		EN1 = 1;		
	if(pwm_right_val == pwm_t)
		EN2 = 1;			 
}

int main(void)
{
	TMOD |= 0x02;
	TH0 = 220;
	TL0 = 220;
	TR0 = 1;
	ET0 = 1;
	EA	= 1;
	while(1)
	{
		
		if (left_find == 0 && right_find == 0)
		{
			advance();
		}
		else
		{
			if (left_find == 1 && right_find == 0)
			{
				left_turn();
			}
			if (left_find == 0 && right_find == 1)
			{
				right_turn();
			}
		}
		if (left_find == 1 && right_find == 1)
		{
			stop();
		}
		
	}
	
}
